package com.software.shipper.dao;

public class ShipperTransaction {

	private ShipperDao shipperDao;

	public ShipperDao getShipperDao() {
		return shipperDao;
	}

	public void setShipperDao(ShipperDao shipperDao) {
		this.shipperDao = shipperDao;
	}
	
	public boolean login(String email,String password){
		Shipper shipper = new Shipper();
		shipper.setEmail(email);
		shipper.setPassword(password);
		Shipper s = shipperDao.queryShipper(shipper);
		if(s != null){
			if(password.equals(s.getPassword())){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 * 前提：判断账户是否已经被注册
	 * @param username
	 * @param password
	 * @param email
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public boolean register(String name,String password, String email,String phone){
		Shipper shipper = new Shipper();
		shipper.setEmail(email);
		shipper.setPassword(password);
		shipper.setPhone(phone);
		shipper.setName(name);
		
		Shipper s = shipperDao.queryShipper(shipper);
		if(s != null){
			return false;
		}
		try{
			shipperDao.addShipper(shipper);
			return true;
		}catch(Exception e){
			return false;
		}	
	}
}
